package com.ruoyi.binding.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.binding.domain.AmRuleBinding;
import com.ruoyi.binding.service.IAmRuleBindingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分佣规则和房源绑定Controller
 * 
 * @author ruoyi
 * @date 2020-07-28
 */
@RestController
@RequestMapping("/binding/binding")
public class AmRuleBindingController extends BaseController
{
    @Autowired
    private IAmRuleBindingService amRuleBindingService;

    /**
     * 查询分佣规则和房源绑定列表
     */
    @PreAuthorize("@ss.hasPermi('binding:binding:list')")
    @GetMapping("/list")
    public TableDataInfo list(AmRuleBinding amRuleBinding)
    {
        startPage();
        List<AmRuleBinding> list = amRuleBindingService.selectAmRuleBindingList(amRuleBinding);
        return getDataTable(list);
    }

    /**
     * 导出分佣规则和房源绑定列表
     */
    @PreAuthorize("@ss.hasPermi('binding:binding:export')")
    @Log(title = "分佣规则和房源绑定", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AmRuleBinding amRuleBinding)
    {
        List<AmRuleBinding> list = amRuleBindingService.selectAmRuleBindingList(amRuleBinding);
        ExcelUtil<AmRuleBinding> util = new ExcelUtil<AmRuleBinding>(AmRuleBinding.class);
        return util.exportExcel(list, "binding");
    }

    /**
     * 获取分佣规则和房源绑定详细信息
     */
    @PreAuthorize("@ss.hasPermi('binding:binding:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(amRuleBindingService.selectAmRuleBindingById(id));
    }

    /**
     * 新增分佣规则和房源绑定
     */
    @PreAuthorize("@ss.hasPermi('binding:binding:add')")
    @Log(title = "分佣规则和房源绑定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AmRuleBinding amRuleBinding)
    {
        return toAjax(amRuleBindingService.insertAmRuleBinding(amRuleBinding));
    }

    /**
     * 修改分佣规则和房源绑定
     */
    @PreAuthorize("@ss.hasPermi('binding:binding:edit')")
    @Log(title = "分佣规则和房源绑定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AmRuleBinding amRuleBinding)
    {
        return toAjax(amRuleBindingService.updateAmRuleBinding(amRuleBinding));
    }

    /**
     * 删除分佣规则和房源绑定
     */
    @PreAuthorize("@ss.hasPermi('binding:binding:remove')")
    @Log(title = "分佣规则和房源绑定", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(amRuleBindingService.deleteAmRuleBindingByIds(ids));
    }
}
